Demo
Miaolei Bao
SphericalKDE.RmdHow to install
This package is called SphericalKDE. To install, run the
following code (in R):
Upon completion, you can run the following code (in R):
Import data
This is a demo vignette for our package. We will use earthquake data with 77 observations contained in the ’spherepc’ package for demonstration. The data record significant earthquakes (8+ Mb magnitude) around the Pacific Ocean since 1900, collected by the U.S. Geological Survey. The data have longitude and latitude coordinates.
library(spherepc)
#> Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display
#> Warning: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'.
# Import earthquake data and select longitude and latitude coordinates
data(Earthquake)
earthquake <- cbind(Earthquake$long, Earthquake$lat)
head(earthquake)
#> [,1] [,2]
#> [1,] -177.657 -28.427
#> [2,] -176.461 -31.080
#> [3,] -175.626 51.499
#> [4,] -174.776 51.520
#> [5,] -174.123 -20.187
#> [6,] -173.562 -14.739Data transformation
We want to transform spherical coordinates (longitude, latitude) to 3-dim Euclidean coordinates for analysis.
earthquake_Euc <- SphericalKDE::transform_coordinates(earthquake)
head(earthquake_Euc)
#> x y z
#> [1,] -0.8786891 -0.03595233 -0.4760387
#> [2,] -0.8548141 -0.05286672 -0.5162344
#> [3,] -0.6207152 -0.04747810 0.7825973
#> [4,] -0.6196568 -0.05665491 0.7828254
#> [5,] -0.9336382 -0.09610335 -0.3450853
#> [6,] -0.9609961 -0.10843841 -0.2544163Cross validation
Then we could use cross validation to select the optimal smoothing parameter \(\kappa\).
Visualization
library(htmlwidgets)
my_plotly_plot <- SphericalKDE::generate_plot(earthquake_Euc, kappa = optimal_kappa)
my_plotly_plot